<?php
/**--------------------
 * Date: 2018/2/2
 * FileName:EditQuestion.php 添加问题
 * ProjectName:ZhiShiRongYao
 * -------------------- */


namespace app\api\controller;


use app\api\ApiBase;
use app\common\model\QuestionsModel;
use think\Db;

class EditQuestion extends ApiBase
{

    /**
     * 获取科目分类
     *
     * @param int $pid 科目parent_id
     *
     * @throws \think\exception\DbException
     * @return string
     */
    public function getSubjectType($pid = 0)
    {
        $subjects = Db::name('knowledge_subject')->field('id,name,logo')->where('parent_id', $pid)->select();
        if ($subjects) {
            return $this->json_success('ok', $subjects);
        }
        return $this->json_error('暂无子科目');
    }


    /**
     * 提交问题
     *
     * @return string
     */
    public function postQuestion()
    {
        $args = input('post.');
        $res  = QuestionsModel::addQuestions($args['subject_id'], $args['title'], serialize($args['answer']), $this->user_info['id'],$this->user_info['display_name'], 0, 1);
        if ($res) {
            return $this->json_success('ok', '题库添加成功');
        }
        return $this->json_error('题库添加失败');
    }
}